//
//  AliPayModel.m
//  sensen_ios
//
//  Created by pro on 16/3/23.
//  Copyright © 2016年 pro. All rights reserved.
//

#import "AliPayModel.h"

@implementation AliPayModel

+ (AliPayModel *)defaultPayModel {
    
    AliPayModel *order = [[AliPayModel alloc] init];
    
    order.seller = GLOBAL_ALIPAY_SELLER;
    order.partner = GLOBAL_ALIPAY_PARTNER;
    order.notifyURL =  GLOBAL_ALIPAY_NOTIFY_URL; //回调URL
    order.inputCharset = @"utf-8";
    order.itBPay = @"30m";
    order.service = @"mobile.securitypay.pay";
    order.paymentType = @"1";
    
    return order;
}

- (NSString *) description {
    
    NSMutableString * desc = [NSMutableString string];
    
#pragma mark -- 默认设置的属性 --
    if (self.partner) {
        [desc appendFormat:@"partner=\"%@\"", self.partner];
    } else {
        DLog(@" partner不能为空 ");
    }
    
    if (self.seller) {
        [desc appendFormat:@"&seller_id=\"%@\"", self.seller];
    } else {
        DLog(@" seller不能为空 ");
    }
    
    if (self.notifyURL) {
        [desc appendFormat:@"&notify_url=\"%@\"", self.notifyURL];
    } else {
        DLog(@" notifyURL不能为空 ");
    }
    
    if (self.inputCharset) {
        [desc appendFormat:@"&_input_charset=\"%@\"",self.inputCharset];//utf-8
    } else {
        DLog(@" inputCharset不能为空 ");
    }
    
    if (self.itBPay) {
        [desc appendFormat:@"&it_b_pay=\"%@\"",self.itBPay];//30m
    } else {
        DLog(@" itBPay不能为空 ");
    }
    
    if (self.service) {
        [desc appendFormat:@"&service=\"%@\"",self.service];//mobile.securitypay.pay
    } else {
        DLog(@" service不能为空 ");
    }
    
    if (self.paymentType) {
        [desc appendFormat:@"&payment_type=\"%@\"",self.paymentType];//1
    } else {
        DLog(@" paymentType不能为空 ");
    }
    
#pragma mark -- 订单相关的属性 --
    // 订单号
    if (self.tradeNO) {
        [desc appendFormat:@"&out_trade_no=\"%@\"", self.tradeNO];
    } else {
        DLog(@" tradeNO不能为空 ");
    }
    // 商品名
    if (self.productName) {
        [desc appendFormat:@"&subject=\"%@\"", self.productName];
    } else {
        DLog(@" productName不能为空 ");
    }
    // 商品描述
    if (self.productDescription) {
        [desc appendFormat:@"&body=\"森森-%@\"", self.productDescription];
    } else {
        DLog(@" body不能为空 ");
    }
    // 订单价格
    if (self.totalFee) {
        [desc appendFormat:@"&total_fee=\"%@\"", self.totalFee];
    } else {
        DLog(@" productName不能为空 ");
    }
    // 展示网页
    if (self.showUrl) {
        [desc appendFormat:@"&show_url=\"%@\"",self.showUrl];//m.alipay.com
    } else {
        DLog(@" showUrl不能为空 ");
    }
    
    
#pragma mark -- 其他可选属性 -- 
    
    if (self.rsaDate) {
        [desc appendFormat:@"&sign_date=\"%@\"",self.rsaDate];
    }
    if (self.appId) {
        [desc appendFormat:@"&app_id=\"%@\"",self.appId];
    }
    for (NSString *key in [self.extraParams allKeys]) {
        [desc appendFormat:@"&%@=\"%@\"", key, [self.extraParams objectForKey:key]];
    }
    
    return desc;
}

@end
